package com.jn.mvvm2.repository;

import com.jn.mvvm2.entity.QAndAEntity;
import com.jn.mvvm2.service.QAndAService;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class QAndARepository {
    public static final String BASE_URL = "https://shanhe.kim/";
    private QAndAService mQAndAService;

    public QAndARepository() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                .build();
        mQAndAService = retrofit.create(QAndAService.class);
    }

    public Observable<QAndAEntity> getData() {
        return mQAndAService.getData("json")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io());
    }
}
